//
//  BattleBackGroundLayer.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-4-10.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//

#import "BattleBackGroundLayer.h"

@implementation BattleBackGroundLayer

-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init])) 
    {
        // ask director the the window size
		CGSize size = [[CCDirector sharedDirector] winSize];
        
        CCSprite* backGround = [CCSprite spriteWithSpriteFrameName:@"battleBackGround.jpg"]; 
        gameLayerPosition = ccp(size.width / 2 , size.height / 2);
        backGround.position = gameLayerPosition;
        [self addChild:backGround];
        self.isTouchEnabled = YES;
    }
	return self;
}

//监听首次触发事件
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CCLOG(@"触摸开始");
}

//触摸事件 - 当手指在屏幕上进行移动
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{  
//    
//        CGPoint currentTouchLocation = [MultiLayerScene locationFromTouch:touch];
//        
//        // 计算当前和之前的触摸之间的距离
//        CGPoint moveTo = ccpSub(lastTouchLocation, currentTouchLocation);
//        
//        // 将计算结果乘以-1,以产生背景在移动的效果 
//        moveTo = ccpMult(moveTo, -1);
//        lastTouchLocation = currentTouchLocation;
//    
//    // 调整层相应的位置,包括层所包含的所有子节点 
//    
//        self.position = ccpAdd(self.position, moveTo);
     CCLOG(@"触摸中");
}

//触摸事件 - 当手指从屏幕抬起时调用的方法
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{  
     CCLOG(@"触摸结束");
}


-(void) registerWithTouchDispatcher
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1
                                              swallowsTouches:YES];
}


-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event
{
//    lastTouchLocation = [self locationFromTouch:touch];
    // 停止之前的移动动作,以免干扰用户的滚动操作
//    [self stopActionByTag:111];
    // 总是吞没触摸事件,GameLayer是最后一个接收到触摸事件的层 
    CCLOG(@"触摸开始1");
    return YES;
}

-(void) ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event
{
//    CGPoint currentTouchLocation = [MultiLayerScene locationFromTouch:touch];
//    
//    // 计算当前和之前的触摸之间的距离
//    CGPoint moveTo = ccpSub(lastTouchLocation, currentTouchLocation);
//    
//    // 将计算结果乘以-1,以产生背景在移动的效果 
//    moveTo = ccpMult(moveTo, -1);
//    lastTouchLocation = currentTouchLocation;
    
    // 调整层相应的位置,包括层所包含的所有子节点 
    
//    self.position = ccpAdd(self.position, moveTo);
    CCLOG(@"触摸中2");
}

-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event
{
    // 将GameLayer移回原先指定的位置
//    CCMoveTo* move = [CCMoveTo actionWithDuration:1 position:gameLayerPosition];
//    CCEaseIn* ease = [CCEaseIn actionWithAction:move rate:0.5f];
//    ease.tag = 111;
//    [self runAction:ease];
    CCLOG(@"触摸结束3");
}

@end
